import request from '@/utils/request'
import qs from 'qs'

export function login(param) {
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic YW5pbWUtZnJvbnQ6c2VjcmV0'
    },
    url: '/oauth/token',
    method: 'post',
    data: qs.stringify(param)
  })
}

export function getInfo() {
  return request({
    url: '/user/info',
    method: 'get',
  })
}

export function logout() {
  return request({
    url: '/user/logout',
    method: 'get'
  })
}

export function checkName(username) {
  return request({
    url: '/user/checkName',
    method: 'get',
    params: {
      username
    }
  })
}

export function register(param) {
  return request({
    url: '/user/register',
    method: 'post',
    data: param
  })
}
